package cn.ming.springbootdynamicdatasourcedemo.service.impl;

import cn.ming.springbootdynamicdatasourcedemo.entiy.SysUser;
import cn.ming.springbootdynamicdatasourcedemo.mapper.UserMapper;
import cn.ming.springbootdynamicdatasourcedemo.service.UserService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description XXX类，用于XXX
 * @Author zhuming
 * @Date 2021-08-01 17:05
 * @Version 1.0.0
 */
@Service
@DS("slave")
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private UserMapper userMapper;
    /**
     * 获取用户列表
     *
     * @return
     */
    @Override
    public List<SysUser> getList() {
        return userMapper.selectList(new QueryWrapper<SysUser>());
    }

    /**
     * 添加新用户
     */
    @DS("master")
    @Override
    public void addUser() {
        SysUser sysUser = new SysUser();
        sysUser.setName("dynamic");
        sysUser.setPassword("1111");
        userMapper.insert(sysUser);
    }
}
